name: Lint

on: [push, pull_request]

permissions:
  contents: read

jobs:
  rails-bin:
    name: Check rails-bin lints
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
      with:
        repository: skipkayhil/rails-bin
        ref: 748f4673a5fe5686b5859e89f814166280e51781
    - uses: ruby/setup-ruby@v1
      with:
        ruby-version: 3.2
        bundler-cache: true
    - uses: actions/checkout@v3
      with:
        path: rails
    - run: bin/check-changelogs ./rails
    - run: bin/check-config-docs ./rails
  codespell:
    name: Check spelling all files with codespell
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: ['3.10']
    steps:
      - uses: actions/checkout@v3
      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v2
        with:
          python-version: ${{ matrix.python-version }}
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install codespell==2.1.0
      - name: Check spelling with codespell
        run: codespell --ignore-words=codespell.txt --skip="./actionview/test/ujs/public/vendor/qunit.js,./actiontext/app/assets/javascripts/trix.js" || exit 1

  notify:
    runs-on: ubuntu-latest
    if: always() && github.ref_name == 'main'
    continue-on-error: true
    needs: [rails-bin, codespell]
    steps:
      - uses: zzak/action-discord@v4
        with:
          webhook: ${{ secrets.DISCORD_WEBHOOK }}
